/*
 * NoRacleVendingMachine.java
 *
 * Created on April 4, 2007, 6:22 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package localSite.vendingMachineDB;

import java.util.LinkedList;
import java.util.ListIterator;

/**
 *
 * @author David Roberts
 */
public class NoRacleVendingMachine
{
    private LinkedList machineList = new LinkedList ();
    
    /** Creates a new instance of NoRacleVendingMachine */
    public NoRacleVendingMachine ()
    {
        System.out.println ("Creating NoRacle VendingMachine Database!");
    }
    
    public boolean AddRecord (VendingMachineRecord R)
    {
        machineList.add (R);
        System.out.println ("Adding Record to NoRacle VendingMachine Database!");
        return true;
    }
    
    public boolean DeleteRecord (int machineID )
    {
        VendingMachineRecord vend;
        ListIterator it = machineList.listIterator ();
        boolean status = false;
        
        while( it.hasNext ())
        {
            vend = (VendingMachineRecord)it.next ();
            if( vend.machineID == machineID )
            {
                status = true;
                System.out.println ("Removing Vending Machine: " + machineID );
                it.remove ();
            }
        }
        
        if (!status)
            System.out.println ("Could not find machine to remove, ID: " + machineID );
        
        return status;
    }
    
    public VendingMachineRecord GetRecord (int machineID)
    {
        VendingMachineRecord vend = null;
        ListIterator it = machineList.listIterator ();
        boolean status = false;
        
        while( it.hasNext ())
        {
            vend = (VendingMachineRecord)it.next ();
            if( vend.machineID == machineID )
            {
                status = true;
                System.out.println ("Getting Record from NoRacle VendingMachine Database!");
                break;
            }
        }
        
        if (!status)
            System.out.println ("Could not find machine, ID: " + machineID );
        
        return vend;
    }
    

}
